package tests.game;

import junit.framework.TestCase;
import game.Tile;
import game.Tile.TileColor;
import game.exceptions.TileException;

public class TileTest extends TestCase {

	/**
	 * Test for Tile constructor.
	 */
	public void testTile() {

		//Test 1:
		try {
			Tile tTile = new Tile(1, TileColor.BLACK);
			assertTrue("New Tile is null.",tTile != null);
			assertEquals("Tile was created with wrong number.",1, tTile.getNumber());
			assertEquals("Tile was created with wrong color.",TileColor.BLACK, tTile.getColor());
		} catch (TileException e) {
			fail("Exception was thrown while tring to create new Tile.\n\r" +
				 "Message: " + e.getMessage());
		}
		
		//Test 2:
		try {
			new Tile(13,TileColor.RED);
			fail("Exception wasn't thrown while trying to create ilegal Tile.");
		} catch (TileException e) {
			System.out.println(e.getMessage());
		}
		
	}

	/**
	 * Test for equals method.
	 * Expected to compare Tile objects by value(those value object).
	 */
	public void testEqualsObject() {
		try {
			Tile tTile1 = new Tile(3,TileColor.YELOW);
			Tile tTile2 = new Tile(3,TileColor.YELOW);
			assertTrue("Tiles with equal values were found not equal.",tTile1.equals(tTile2));
			Tile tTile3 = new Tile(5,TileColor.YELOW);
			assertTrue("Tiles with not equal numbers values were found equal.",!tTile1.equals(tTile3));
			Tile tTile4 = new Tile(3,TileColor.RED);
			assertTrue("Tiles with not equal colors were found equal.",!tTile1.equals(tTile4));
		} catch (TileException e) {
			fail("Exception was thrown while tring to create new Tile.\n\r" +
			     "Message: " + e.getMessage());
		}
	}

}
